package todolist.test;

import java.util.List;

import todolist.activities.FilterActivity;
import todolist.activities.ListScreenActivity;
import todolist.activities.RegisterActivity;
import todolist.activities.TodoList;
import todolist.helpers.taskDataSource;
import todolist.structures.Task;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.widget.CheckBox;
import android.widget.TextView;

public class JUnitFilterScreenActivity extends ActivityInstrumentationTestCase2<FilterActivity> {
	private FilterActivity mActivity;  // the activity under test
    TodoList context;
    CheckBox check;
    CheckBox dateBox;
    
    public JUnitFilterScreenActivity() {
      super("todolist.activities", FilterActivity.class);
    }
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mActivity = this.getActivity();
        context = ((TodoList) mActivity.getApplicationContext());
        check=(CheckBox) mActivity.findViewById(todolist.activities.R.id.dateBox);
        dateBox=(CheckBox) mActivity.findViewById(todolist.activities.R.id.dateBox);
    }
    public void testPreconditions() {
      assertNotNull(mActivity);
    }
    
    /*
     * These tests achieve branch coverage for both the date checkbox, and completed item checkboxes
     */
	
    //Test to ensure that the showcomplete method return false when checkbox checked
    public void testShowCompletedFalse() {
		if(check.isChecked()){
			assertFalse(context.isShowComplete());
		}
	}
    
  //Test to ensure that the showcomplete method return true when checkbox checked
	public void testShowCompletedTrue() {
		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
		sendKeys(KeyEvent.KEYCODE_DPAD_UP);
		sendKeys("ENTER");
		if(check.isChecked()){
			assertTrue(context.isShowComplete());
		}
	}
	 
    //Test to ensure that the isFilterByDate method return true when datechecked
    public void testDateCheckedTrue() {
		if(dateBox.isChecked()){
			assertFalse(context.isFilterByDate());
		}
	}

  //Test to ensure that the isFilterByDate method return false when datechecked
    public void testDateCheckedFalse() {
		if(dateBox.isChecked()){
			assertFalse(context.isFilterByDate());
		}
	}
}
